

//
//  OpenInvoiceViewController.m
//  didihaha
//
//  Created by 赵忠鹏 on 2017/8/14.
//  Copyright © 2017年 zhaozhongpeng. All rights reserved.
//

#import "OpenInvoiceViewController.h"

@interface OpenInvoiceViewController ()

@property (nonatomic, strong)UIView *topView;

@property (nonatomic, assign)CGFloat num;

@property (nonatomic, weak)NSTimer *timer;

@end

@implementation OpenInvoiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setTitle:@"开具发票"];
    [self setLeftBackButton];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.topView];
    self.num = arc4random()%100;
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.top.equalTo(self.view).offset(64);
        make.width.mas_equalTo(self.num);
        make.height.mas_equalTo(2);
    }];
    
     NSTimer *timer = [NSTimer timerWithTimeInterval:2 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    self.timer = timer;
     [[NSRunLoop mainRunLoop] addTimer:timer forMode: NSRunLoopCommonModes];
}

- (void)backPop{
    [self.navigationController popViewControllerAnimated:YES];
    [self.timer invalidate];
}

- (void)timerAction{
    self.num+= arc4random()%20;
    
    [self.view layoutIfNeeded];
    
    [UIView animateWithDuration:1.2 animations:^{
        
        [self.topView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(self.num);
        }];
        
        if (self.num > (kScreenWidth * 2/3)) {
            [self.timer invalidate];
//            [MBProgressHUD showTextOnly:@"服务器网络异常"];
        }
        
        [self.view layoutIfNeeded];
    }];
    
    
    
}

- (UIView *)topView{
    if (_topView == nil) {
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = [UIColor orangeColor];
    }
    return _topView;
}

@end
